package com.sromku.simple.fb.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.example.hal.model.Activite;
import com.example.hal.model.ActiviteController;
import com.example.hal.model.Utilisateur;
import com.example.hal.model.UtilisateurController;
import com.sromku.simple.fb.SimpleFacebook;
import com.sromku.simple.fb.example.fragments.LoginFragment;
import com.sromku.simple.fb.example.utils.Utils;

public class InscriptionActivity extends FragmentActivity {
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_inscription);

	Button btn = (Button) findViewById(R.id.inscriptionNow);
	btn.setOnClickListener(new OnClickListener() {

	    @Override
	    public void onClick(View v) {
			creerCompte();
	    }
	});
    }

    final void creerCompte()
    {
	final Thread checkUpdate = new Thread() {
	    public void run() {
			EditText nom = (EditText) findViewById(R.id.nomInscription);
			EditText prenom = (EditText) findViewById(R.id.prenomInscription);
			EditText email = (EditText) findViewById(R.id.emailInscription);
			EditText passeword = (EditText) findViewById(R.id.passeInscription);
			
		Utilisateur u = new Utilisateur();
		u.setNom(nom.getText().toString());
		u.setPrenom(prenom.getText().toString());
		u.setEmail(email.getText().toString());
		u.setMdp(passeword.getText().toString());
		final UtilisateurController uc = new UtilisateurController();
		try {
		    uc.create(u);
		} catch (Exception e) {
		    return;
		}
		final Intent intent = new Intent(InscriptionActivity.this,
				MainActivity.class);
		startActivity(intent);
		finish();
	    }
	};
	checkUpdate.start();
    }
}
